import React, {Component} from 'react';
import {
  Layout,
  Menu,
  Breadcrumb,
  Modal,
  Form,
  Input,
  Select,
  DatePicker,
  Popconfirm,
  Card,
  Row,
  Col,
  Button,
  Radio,
  Dropdown,
  Icon,
  Upload,
  message,
  Table,
  Pagination,
  Checkbox
} from 'antd';
const FormItem = Form.Item;
const {Header, Content, Footer} = Layout;
import _ from 'underscore';
import WrapPage from './_wrap'
import styles from './main.less'
import {Link} from 'dva/router';
import StockListModal from './component/inputlist_stock_list';
import * as  CustomerModel from '../model/customer';
import * as InputModel from '../model/input';
import * as  StockModel from '../model/stock';
import * as  ProductModel from '../model/product';

 class _Page extends React.Component {
    constructor(props) {
        super(props);
        this.state = {page:1,pageSize:9999,orderBy:'createAt',filter:{},data:{list:[]},flag:false,visible1:false,};
        this.list()
      }
      async list(){
        var res = await  InputModel.fetch({
            filter:{status:"finish"},
            limit:1000000,
        })
        if(res.status == 'success'){
          for(let input of res.data.list){
            if(_.isEmpty(input.components)===false){
                for(let comp of input.components){
                  if(comp.stock_num){
                    let com=await StockModel.getByNum(comp.stock_num)
                    comp.stock=com.data.item || {};
                  }
                }
            }
          }
        }
        this.setState({data:res.data});
      }
      showModelHandler =async (e) => {
        if (e) e.stopPropagation();
          this.setState({
            visible1: true,
          });
      }
      handleSubmit =async (e) => {
        if (e) e.stopPropagation();
          this.setState({
            visible1: false,
          });
      }
      hideModelHandler =async (e) => {
        if (e) e.stopPropagation();
          this.setState({
            visible1: false,
          });
      }
  render() {
    const {children}=this.props;
         const columns = [
           {
             title: '入库编号',
             dataIndex: 'cnum',
             key: 'cnum',
             render: (text,record) =>
             (<span>{text}</span>),
           },
           {
             title: '类型',
             dataIndex: 'itype',
             key: 'itype',
             render: text =>
             (<span>{text==="purchase"?'采购入库':'其他入库'}</span>),
           },{
             title: '提箱单号',
             dataIndex: 'suitcase_num',
             key: 'suitcase_num',
             render: (text,record) =>
             (<span>{text}</span>),
           },{
             title: '现货列表',
             dataIndex: 'Operation',
             key: 'Operation',
             render: (text,record) =>
             (<span>
                 <StockListModal record={record}>
                   <span style={{cursor:"pointer"}}>查看详情</span>
                 </StockListModal>
             </span>),
           }
         ];

    return (
      <WrapPage>
        <div>
                 <Row>
                   <Col span={12}>查看已入库</Col>
                   <Col span={12}>
                       <Row type="flex" justify="end">
                             <Link to="/container"><Button title="返回"><Icon type="caret-left" />返回</Button></Link>
                       </Row>
                   </Col>
                 </Row>
                 <Table columns={columns} dataSource={this.state.data.list}
                     rowKey={record => record.cnum} pagination={false} scroll={{ x: 1000}}/>
             </div>
      </WrapPage>
    );
  }
}

export default _Page
